package com.android.sharecar.activity.config;

import com.android.sharecar.activity.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TimePicker;

/**
 * This activity configures the user's path to work and back.
 * @author Administrator
 *@date 2011-9-14
 */
public class ConfigPathActivity extends Activity {
	private Button mPositive, mCancel;
	private TimePicker mToWorkTime, mOffWorkTime; // 上班出发时间，下班出发时间
	private EditText mToWorkPlace, mOffWorkPlace; // 上班出发地，下班出发地
	private EditText mRestDay; // 休息日
	private Spinner mVacantSeatNum; // 空座数量

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.workpath);

		// get objects
		mPositive = (Button) findViewById(R.id.configWorkPath_btn_positive);
		mCancel = (Button) findViewById(R.id.configWorkPath_btn_cancel);
		mToWorkTime = (TimePicker) findViewById(R.id.configWorkPath_tp_toWorkTime);
		mOffWorkTime = (TimePicker) findViewById(R.id.configWorkPath_tp_offWorkTime);
		mToWorkPlace = (EditText) findViewById(R.id.configWorkPath_et_toWorkPlace);
		mOffWorkPlace = (EditText) findViewById(R.id.configWorkPath_et_offWorkPlace);
		mRestDay = (EditText) findViewById(R.id.configWorkPath_et_restDay);
		mVacantSeatNum = (Spinner) findViewById(R.id.configWorkPath_sp_vacantSeatNum);

		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.select_dialog_vacantSeatNum,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mVacantSeatNum.setAdapter(adapter);

	}

	private void setListenerForMembers() {
		mCancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				ConfigPathActivity.this.finish();
			}
		});

		mRestDay.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					new AlertDialog.Builder(ConfigPathActivity.this)
							.setIcon(null)
							.setTitle(R.string.restDay)
							.setMultiChoiceItems(
									R.array.select_dialog_restDay,
									new boolean[] { false, false, false, false,
											false, true, true },
									new DialogInterface.OnMultiChoiceClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton,
												boolean isChecked) {

											// User clicked on a check box do
											// some stuff
										}
									})
							.setPositiveButton(R.string.positive,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											// User clicked Yes so do some stuff
											dialog.dismiss();
										}
									})
							.setNegativeButton(R.string.cancel,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											// User clicked No so do some stuff
											dialog.dismiss();
										}
									}).create().show();

					return true;
				}
				return false;
			}
		});
	}
}
